
let __enums = {} 

export function EnumUtility() { }

EnumUtility.prototype.Set = function (data) {
    if (!Array.isArray(data)) {//枚举输入参数必须是数组
        return false;
    }
    if (data.length == 0) {//枚举输入参数不能为空
        return false;
    }
    for (var item in __enums) {//枚举数据已存在,不允许重复赋值 
        return false;
    }

    data.forEach(function (item) {
        // 如果枚举值 为空把当前值设置为空
        if (!__enums[item.enumType]) {
            __enums[item.enumType] = [];
        }
        let enum_obj={
            enumType:item.enumType,
            value:item.value,
            text:item.text
        }
        __enums[item.enumType].push(enum_obj);
    })
    // {"status":[{"enumType":"status","value":"0","text":"启用"},{"enumType":"status","value":"1","text":"禁用"}],"user_type":[{"enumType":"user_type","value":"1","text":"超级管理员"},{"enumType":"user_type","value":"2","text":"普通员工"}]}
    console.log('__enums=',__enums)
    return true;
}

// EnumUtility.prototype.Routerlist = function (DATA) {
//     __enums['Routerlist'] = DATA
// }
// EnumUtility.prototype.GetRouterlist = function (type) {
//     if (!type) return []; 
//     return __enums[type] || []
// }
EnumUtility.prototype.ClearAll = function () {
    __enums = {}
}


EnumUtility.prototype.Get = function (type) {

    if (!type) return []; 
    return __enums[type] || [];
}

EnumUtility.prototype.Gets = function (types) {
    if (!types) return __enums;
    var data = [];
    types.split(",").forEach(function (item) {
        data.push(__enums[item]);
    })
    return data;
}

EnumUtility.prototype.GetTitle = function (type, value) {
    var data = this.Get(type)
    var result = value;
    data.forEach(function (item) {
        if (item.value == value) {
            result = item.text
            return;
        }
    })
    return result;
}
